const preurl="http://www.pudge.wang:5000/api"
const http={
    getData(url,obj){
        if(obj){
            let myarr=Object.keys(obj);
            myarr=myarr.map((item=>item+"="+obj[item]));
            let str=myarr.join("&");
            url+=("?"+str);
        }
        return  fetch(preurl+url)
        .then(res=>res.json())
        .then(res=>{
            if(res.status===0){
                return res;
            }else{
                throw new Error(res.msg);
            }
        });
    },
    postData(url,obj){
        return fetch(preurl+url,{
            method:'post',
            body:JSON.stringify(obj),
            headers:{
                "Content-Type": "application/json",
            }
        }).then(res=>res.json())
        .then(res=>{
            if(res.status===0){
                return res;
            }else{
                throw new Error(res.msg);
            }
        });
    }
}

export default http;